package com.fishingwithme.infrastructure.dtos;

import com.fishingwithme.domain.user.SpotUser;
import lombok.Data;
import org.assertj.core.util.Lists;

import java.util.Date;
import java.util.List;

@Data
public class UserInfoDto {
    private Long id;
    private String username;
    private String password;
    private String openId;
    private Long phoneNo;
    private Date registerTime;
    private String email;

    private Long userId;

    private String unionId;

    private String nickname;

    private String avatarUrl;

    private Integer gender;

    private String city;

    private String province;

    private String country;

    private boolean admin;

    private Date createdAt;

    private Date updatedAt;

    private List<String> roles;

    public static UserInfoDto from(SpotUser spotUser) {
        if (spotUser == null) {
            return null;
        }
        UserInfoDto info = new UserInfoDto();
        if(spotUser.isAdmin()) {
            info.setRoles(Lists.newArrayList("ROLE_ADMIN"));
        } else {
            info.setRoles(Lists.newArrayList("ROLE_USER"));
        }
        info.setId(spotUser.getUserId());
        info.setUsername(spotUser.getUsername());
        info.setNickname(spotUser.getNickname());
        info.setAvatarUrl(spotUser.getAvatarUrl());
        info.setGender(spotUser.getGender());
        info.setCity(spotUser.getCity());
        info.setProvince(spotUser.getProvince());
        info.setCountry(spotUser.getCountry());
        info.setEmail(spotUser.getEmail());
        info.setAdmin(spotUser.isAdmin());
        info.setCreatedAt(spotUser.getCreatedAt());
        info.setUpdatedAt(spotUser.getUpdatedAt());
        info.setUserId(spotUser.getUserId());
        return info;
    }
}
